import request, {upload} from "@/utils/request"
import type {
  AuthInfoDTO, AuthStatusVO,
  DetailInfoVO,
  DriverLicenseOcrVO,
  IdCardOcrVO,
  LoginDTO,
  LoginVO,
  PasswordDTO,
  RegisterDTO,
  UserInfoVO
} from "@/types/user"

/** 用户登录 */
export const loginAPI = (data: LoginDTO) => {
  return request<LoginVO>({
    method: "POST",
    header: {
      isToken: false
    },
    url: "/user/user/login",
    data
  })
}

/** 用户注册 */
export const registerAPI = (data: RegisterDTO) => {
  return request<null>({
    method: "POST",
    header: {
      isToken: false
    },
    url: "/user/user/register",
    data
  })
}

/** 退出登录 */
export const logoutAPI = () => {
  return request<null>({
    method: "DELETE",
    url: "/user/user/logout"
  })
}

/** 获取用户信息 */
export const getUserInfoAPI = () => {
  return request<UserInfoVO>({
    method: "GET",
    url: "/user/user/userInfo"
  })
}

/** 上传文件 */
export const uploadAPI = (filePath: string) => {
  return upload<string>({
    url: "/user/cloud/upload",
    filePath
  })
}

/** 获取用户详细信息 */
export const getDetailInfoAPI = () => {
  return request<DetailInfoVO>({
    method: "GET",
    url: "/user/user/detailInfo"
  })
}

/** 更新用户信息 */
export const updateUserInfoAPI = (data: DetailInfoVO) => {
  return request<null>({
    method: "PUT",
    url: "/user/user/userInfo",
    data
  })
}

/** 修改密码 */
export const modifyPasswordAPI = (data: PasswordDTO) => {
  return request<null>({
    method: "PUT",
    url: "/user/user/password",
    data
  })
}

/** 获取司机认证状态 */
export const getDriverAuthStatusAPI = () => {
  return request<AuthStatusVO>({
    method: "GET",
    url: "/user/driver/authStatus"
  })
}

/** 身份证识别 */
export const idCardOcrAPI = (filePath: string) => {
  return upload<IdCardOcrVO>({
    url: "/user/cloud/idCardOcr",
    filePath
  })
}

/** 驾驶证识别 */
export const driverLicenseOcrAPI = (filePath: string) => {
  return upload<DriverLicenseOcrVO>({
    url: "/user/cloud/driverLicenseOcr",
    filePath
  })
}

/** 创建或更新司机认证信息 */
export const createOrUpdateDriverAuthInfoAPI = (data: AuthInfoDTO) => {
  return request<null>({
    method: "POST",
    url: "/user/driver/authInfo",
    data
  })
}
